/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bea.cliente.gui.builders;

import bea.cliente.gui.styles.ButtonStyles;
import bea.cliente.gui.styles.FontsStyles;
import bea.cliente.gui.styles.WindowStyles;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.builder.TextBuilder;
import de.lessvoid.nifty.controls.DropDown;
import de.lessvoid.nifty.controls.button.builder.ButtonBuilder;
import de.lessvoid.nifty.controls.checkbox.builder.CheckboxBuilder;
import de.lessvoid.nifty.controls.dropdown.builder.DropDownBuilder;
import de.lessvoid.nifty.controls.window.builder.WindowBuilder;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.tools.Color;
import java.util.ArrayList;

/**
 *
 * @author ivan
 */
public class GraphicsOptionsWindowBuilder {

    /**
     * Constante com os valores possiveis de resolução
     */
    public static final ArrayList<String> RESOLUTIONS = new ArrayList<String>();

    static {
        RESOLUTIONS.add("800x600");
        RESOLUTIONS.add("1024x768");
        RESOLUTIONS.add("1400x900");
        RESOLUTIONS.add("1600x1050");
    }
    /**
     * Constante com os valores possiveis de framerate
     */
    public static final ArrayList<String> FRAMERATE = new ArrayList<String>();

    static {
        FRAMERATE.add("stable");
        FRAMERATE.add("60");
        FRAMERATE.add("80");
        FRAMERATE.add("100");
    }
    /**
     * Constante com os valores possiveis de antialiasings
     */
    public static final ArrayList<String> ANTIALIASINGS = new ArrayList<String>();

    static {
        ANTIALIASINGS.add("no");
        ANTIALIASINGS.add("2");
        ANTIALIASINGS.add("4");
        ANTIALIASINGS.add("8");
    }
    /**
     * atributos da janela
     */
    public static String WINDOW_ID = "graphicsOptionsWindow";
    public static String TITLE = "Graphics";
    public static String WIDTH = "300px";
    public static String HEIGHT = "400px";
    public static final int NUM_LEFT_LABELS = 5;
    /**
     * ids de identificações dos itens de configurações graficas
     */
    public static String DDL_RESOLUTION_ID = "ddlResolutionOptions";
    public static String DDL_FRAMERATE_ID = "ddlFrameRateOptions";
    public static String DDL_ANTIALIASING_ID = "ddlAntialiasingOptions";
    public static String CHK_FULLSCREEN_ID = "chkFullScreenOption";
    public static String CHK_VERTICALSYNC_ID = "chkVerticalSyncOption";

    /**
     * 
     * @param nifty
     * @param screen
     * @param parent
     * @return <code>Element</code> janela de configurações graficas do jogo
     */
    public static Element build(Nifty nifty, Screen screen, Element parent) {
        Element graphicsWindow = new WindowBuilder(WINDOW_ID, TITLE) {

            {
                style(WindowStyles.BLACK_STYLE);
                width(WIDTH);
                height(HEIGHT);
                parameter("hideOnClose", "true");
                parameter("closeable", "true");
                parameter("visible", "false");
                parameter("controller", "bed.cliente.gui.controllers.GraphicsOptionsWindowController");
            }
        }.build(nifty, screen, parent);

        // recupera o panel de conteudo da janela
        //Element windowContent = screen.findControl(WINDOW_ID, WindowControl.class).getContent();
        Element windowContent = graphicsWindow.findElementByName("#window-content");
        // adiciona ao panel de conteudo os demais itens da janel
        windowContent.add(new PanelBuilder() {

            {
                width(percentage(100));
                height(percentage(100));
                childLayoutVertical();

                panel(new PanelBuilder() {

                    {
                        height(percentage(90));
                        width(percentage(100));
                        color(Color.randomColor());
                        childLayoutHorizontal();
                        // painell dos labels a esquerda
                        panel(new PanelBuilder() {

                            {
                                childLayoutVertical();
                                width(percentage(50));
                                height(percentage(100));
                                paddingLeft("20px");

                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        childLayoutCenter();
                                        alignLeft();
                                        text(new TextBuilder() {

                                            {
                                                style(FontsStyles.GENERAL_WHITE_TEXT_16);
                                                text("Resolution: ");
                                                backgroundColor("#FFF0");
                                                valignCenter();
                                            }
                                        });
                                    }
                                });

                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        childLayoutCenter();
                                        alignLeft();
                                        text(new TextBuilder() {

                                            {
                                                style(FontsStyles.GENERAL_WHITE_TEXT_16);
                                                text("Full Screen: ");
                                                backgroundColor("#FFF0");
                                                valignCenter();
                                            }
                                        });
                                    }
                                });

                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        childLayoutCenter();
                                        alignLeft();
                                        text(new TextBuilder() {

                                            {
                                                style(FontsStyles.GENERAL_WHITE_TEXT_16);
                                                text("Frame Rate: ");
                                                backgroundColor("#FFF0");
                                                valignCenter();
                                            }
                                        });
                                    }
                                });

                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        childLayoutCenter();
                                        alignLeft();
                                        text(new TextBuilder() {

                                            {
                                                style(FontsStyles.GENERAL_WHITE_TEXT_16);
                                                text("Antialiasing: ");
                                                backgroundColor("#FFF0");
                                                valignCenter();
                                            }
                                        });
                                    }
                                });

                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        childLayoutCenter();
                                        alignLeft();
                                        text(new TextBuilder() {

                                            {
                                                style(FontsStyles.GENERAL_WHITE_TEXT_16);
                                                text("Vertical Sync: ");
                                                backgroundColor("#FFF0");
                                                valignCenter();
                                            }
                                        });
                                    }
                                });
                            }
                        });

                        // painell dos itens "inputs" a direita
                        panel(new PanelBuilder() {

                            {
                                childLayoutVertical();
                                width(percentage(50));
                                height(percentage(100));

                                panel(new PanelBuilder() {

                                    {

                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        width(percentage(100));
                                        childLayoutCenter();

                                        control(new DropDownBuilder(DDL_RESOLUTION_ID) {

                                            {
                                                width("120px");
                                                valignCenter();
                                            }
                                        });
                                    }
                                });

                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        width(percentage(100));
                                        childLayoutCenter();
                                        control(new CheckboxBuilder(CHK_FULLSCREEN_ID) {

                                            {
                                                valignCenter();
                                                alignCenter();
                                            }
                                        });
                                    }
                                });

                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        width(percentage(100));
                                        childLayoutCenter();

                                        control(new DropDownBuilder(DDL_FRAMERATE_ID) {

                                            {
                                                width("120px");
                                                valignCenter();
                                            }
                                        });
                                    }
                                });


                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        width(percentage(100));
                                        childLayoutCenter();

                                        control(new DropDownBuilder(DDL_ANTIALIASING_ID) {

                                            {
                                                width("120px");
                                                valignCenter();
                                            }
                                        });
                                    }
                                });

                                panel(new PanelBuilder() {

                                    {
                                        height(percentage(100 / NUM_LEFT_LABELS));
                                        width(percentage(100));
                                        childLayoutCenter();
                                        control(new CheckboxBuilder(CHK_VERTICALSYNC_ID) {

                                            {
                                                valignCenter();
                                                alignCenter();
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });

                panel(new PanelBuilder() {

                    {
                        width(percentage(100));
                        height(percentage(10));
                        childLayoutHorizontal();

                        // painel contendo o botao "OK"
                        panel(new PanelBuilder() {

                            {
                                height(percentage(100));
                                width(percentage(33));
                                childLayoutCenter();
                                alignCenter();
                                control(new ButtonBuilder("btnGraphicsOptionsOK", "OK") {

                                    {
                                        style(ButtonStyles.BED_BASIC);
                                        alignCenter();
                                        valignCenter();
                                        width("80px");
                                    }
                                });
                            }
                        });

                        // painel contendo o botao "APPLY"
                        panel(new PanelBuilder() {

                            {
                                height(percentage(100));
                                width(percentage(33));
                                childLayoutCenter();
                                alignCenter();
                                control(new ButtonBuilder("btnGraphicsOptionsApply", "APPLY") {

                                    {
                                        style(ButtonStyles.BED_BASIC);
                                        alignCenter();
                                        valignCenter();
                                        width("80px");
                                    }
                                });
                            }
                        });

                        // painel contendo o botao "CANCEL"
                        panel(new PanelBuilder() {

                            {
                                height(percentage(100));
                                width(percentage(33));
                                childLayoutCenter();
                                alignCenter();
                                control(new ButtonBuilder("btnGraphicsOptionsCancel", "CANCEL") {

                                    {
                                        style(ButtonStyles.BED_BASIC);
                                        alignCenter();
                                        valignCenter();
                                        width("80px");
                                    }
                                });
                            }
                        });
                    }
                });
            }
        }.build(nifty, screen, windowContent));

        // configura as opções de resolução
        DropDown dropDownResolution = windowContent.findNiftyControl(DDL_RESOLUTION_ID, DropDown.class);
        dropDownResolution.addAllItems(RESOLUTIONS);
        // configura as opções de frame rate
        DropDown dropDownFrameRate = windowContent.findNiftyControl(DDL_FRAMERATE_ID, DropDown.class);
        dropDownFrameRate.addAllItems(FRAMERATE);
        // configura as opções de antialiasing
        DropDown dropDownAntialiasing = windowContent.findNiftyControl(DDL_ANTIALIASING_ID, DropDown.class);
        dropDownAntialiasing.addAllItems(ANTIALIASINGS);

        return graphicsWindow;
    }
}
